package com.sky.city.interceptor;

import android.text.TextUtils;
import android.util.Log;


import org.jetbrains.annotations.NotNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 全部token使用
 */

public class VersionTokenInterceptor implements Interceptor {
    private String TAG = "TokenInterceptor";

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request original = chain.request();//原先请求
        String token = "";
//        if (LoginUtilsManager.newInstance().getUserData().getData() == null) {
//            token = "";
//        } else {
//            token = LoginUtilsManager.newInstance().getUserData().getData().getToken();
//        }
        Request request = null;
        if (!TextUtils.isEmpty(token)) {
            request = original.newBuilder()//建立新的请求
                    .header("token", token)
//                  .header("sign", "")//暂时不使用
                    .header("version", "v2")
                    .header("system", "Android")
                    .header("distributor", "1")
                    .method(original.method(), original.body())
                    .build();
        } else {
            request = original.newBuilder()//建立新的请求
                    .header("version", "v2")
                    .header("system", "Android")
                    .header("distributor", "1")
                    .method(original.method(), original.body())
                    .build();
        }

        Log.e(TAG, "request:" + request.toString());
        return chain.proceed(request);//重新请求
    }
}
